<?php
/**
 * @category   Ahs
 * @package    Ahs_Validate
 * @author     Olivier Parent
 * @copyright  Copyright (c) 2011 Artevelde University College Ghent
 */
class Ahs_Validate_EmailInUse extends Zend_Validate_Abstract // Zie: http://framework.zend.com/manual/en/zend.validate.writing_validators.html
{
    const MSG_EMAIL_IN_USE = 'msgEmailInUse';

    protected $_messageTemplates = array(
        self::MSG_EMAIL_IN_USE => "'%value%' is already in use"
    );

    public function isValid($value)
    {
        $this->_setValue($value);
        
        $userMapper = new Application_Model_UserMapper();
        
        $user = $userMapper->fetchByEmail($value);
        
        // Zend_Debug::dump($user->Id);
 
        if ($user->Id !== null) {
            $this->_error(null);
            return false;
        }
 
        return true;
    }
}
